"""
author:         ambitiouscat
email:          zw.ambitiouscat@gmail.com
time:           2021年4月6日 15:28:52
"""
from django.db import models
from django.contrib.auth.models import AbstractUser
from base_object.BaseModel import BaseModel
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings
from data.language.l_import import *
from freeResource.global_setting import G_CharLength

# Create your models here.


class User(AbstractUser,BaseModel):
    """用户模型"""
    def generate_active_token(self):
        serializer = Serializer(settings.SECRET_KEY);
        info = {'confirm':self.id}
        token = Serializer.dumps(info);
        return token.decode();

    class Meta:
        db_table = 'fr_user';
        verbose_name = l_user_verbose_name
        verbose_name_plural = l_user_verbose_name_pluarl

    def __str__(self):
        return self.username;

class Address(BaseModel):
    """
    地址模型
    """
    user = models.ForeignKey(verbose_name='用户名',to='User',on_delete=models.CASCADE);
    receiver = models.CharField(verbose_name='收件人',max_length=G_CharLength.L_Name);
    addr = models.CharField(verbose_name='收件地址',max_length=G_CharLength.L_Addr);
    postcode = models.CharField(verbose_name='邮政编码',max_length=G_CharLength.L_Postcode);
    phone_number = models.CharField(verbose_name='手机号码',max_length=G_CharLength.L_PhoneNumber);
    is_default = models.BooleanField(verbose_name='是否默认地址',default=False);

    class Meta:
        db_table = 'fr_address';
        verbose_name = l_addr_verbose_name
        verbose_name_plural = l_addr_verbose_name_pluarl

    def __str__(self):
        return self.receiver